﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Threading;

namespace TekaMUD.Engine.Framework
{
	public class BlockingFibHeap<T> : FibonacciHeap<T>
		where T:class
	{
		private object SyncRoot = new object();

		/// <summary>
		/// Remove all objects from the Queue.
		/// </summary>
		public new void Clear()
		{
			lock (SyncRoot)
			{
				base.Clear();
			}
		}

		/// <summary>
		/// Removes and returns the object at the beginning of the Queue.
		/// </summary>
		/// <returns>Object in queue.</returns>
		public new Node<T> RemoveMin()
		{
			lock (SyncRoot)
			{
				while (base.Size == 0)
				{
					Monitor.Wait(SyncRoot);
				}
				return base.RemoveMin();
			}
		}

		/// <summary>
		/// Adds an object to the end of the Queue.
		/// </summary>
		/// <param name="obj">Object to put in queue</param>
		public new void Insert(T obj, long key)
		{
			lock (SyncRoot)
			{
				base.Insert(obj, key);
				Monitor.Pulse(SyncRoot);
			}
		}
	}
}